"use strict";
const path = require("path");
const webpack = require("webpack");
const proxyPath = require("./backend");

function resolve(dir) {
    return path.join(__dirname, dir);
}

// 环境
const env = process.env.NODE_ENV === "production" ? true : false;
// 端口
const port = process.env.port || process.env.npm_config_port || 6688; // 端口
// 项目名称
const projectName = "datacenter";

module.exports = {
    publicPath: `/${projectName}/`,
    outputDir: projectName,
    assetsDir: env ? "static" : "",
    css: {
        loaderOptions: {
            less: {
                javascriptEnabled: true
            }
        }
    },
    configureWebpack: config => {
        config.plugins.push(
            new webpack.BannerPlugin(
                "东软汉枫医疗科技有限公司版权所有，翻版必究"
            )
        );
    },
    chainWebpack: config => {
        config.resolve.alias.set("@", resolve("src"));
        config.plugin('chunkPlugin').use(webpack.optimize.LimitChunkCountPlugin, [{
            maxChunks: 10, // 必须大于或等于 1，此处设置成最多生成5个chuank.js文件
            // minChunkSize: 10000
        }])
    },
    //  chainWebpack: (config) => {
    //     config.module
    //      .rule('images')
    //      .test(/\.(png|jpg|jpeg|gif|svg)$/)
    //      .use('image-webpack-loader')
    //      .loader('image-webpack-loader')
    //      .end()
    //      .use('file-loader')
    //      .loader('file-loader')
    //      .options({
    //         name: 'images/[name].[ext]',
    //       })
    //      .end();
    //   },
    // 全局使用less变量
    pluginOptions: {
        'style-resources-loader': {
            preProcessor: 'less'
        }
    },
    lintOnSave: false,
    productionSourceMap: false,
    devServer: {
        host: "0.0.0.0",
        port: port,
        open: true,
        proxy: proxyPath
    }
};
